Skip to content

feat(toolkit): re-walk SCTP chunks with RFC 9260 padding where dpkt misreads unaligned chunks (#3217) - #3219

Open
JarryShaw wants to merge 1 commit into
developfrom
feat/3217-dpkt-sctp-padding
Open

JarryShaw wants to merge 1 commit into
developfrom
feat/3217-dpkt-sctp-padding

Conversation

@JarryShaw

@JarryShaw JarryShaw commented Nov 29, 2026 •

Copy link
Copy Markdown
Owner

Please follow the guide below

  • Put an x into every box [ ] that applies to your pull request (like this: [x])

  • Use the Preview tab to see how your pull request will look

  • Searched for similar pull requests

  • Followed the coding style (make pylint, make mypy, make isort)

  • make test passes, and a test case covers the change

  • Described the user-visible change below and left its changelog entry to the maintainer, keeping docs/source/changelog/ and CHANGELOG.md out of the diff, if the change is user-visible: N/A — centralised

What is the purpose of your pull request?

Tick the commit type your subject line carries.

  • fix — corrects a defect

  • feat — adds a feature

  • perf — changes performance, not behaviour

  • refactor — changes neither behaviour nor performance

  • test — tests only

  • docs — documentation only

  • ci — workflows or build tooling

  • release — bumps the version or rolls up a distribution

  • chore — anything else

  • Also tick if it regenerates constant or registry tables, members keeping their numeric values (the const label)


Description of your pull request and other information

Closes #3217.

  • dpkt 1.9.8 pads DATA chunks alone, so after any other unaligned chunk it misplaces the rest, and where one ends the packet it decodes no SCTP layer, keeping the octets as the IP payload. toolkit.dpkt._sctp_chunks then walks the chunks again from the SCTP octets, each padded to four octets (RFC 9260 §3.2) and stopping at a Length below the chunk header, as the default engine's chunk list does; the records are then toolkit.pcap.sctp_reassembly's wherever that engine decodes the SCTP layer.
  • The octets are those dpkt kept, or, for a layer it decoded, the record octets the engine attaches, cut where dpkt cut the IP payload. _sctp_carrier returns kept octets, but not a later fragment's.
  • Gap left, on the engines page's DPKT row: behind VLAN tag stacks whose layers dpkt's own lengths misplace (fix(toolkit): dpkt ends the extraction with ProtocolError on 802.1Q then 802.1ad, two 802.1ad, or three VLAN tags #1646), the record octets cannot be sliced, so the chunks after a misplaced one stay unread, as for a packet built by hand.
  • Divergences, pinned: where the IP length or the capture cuts a last chunk inside its padding, the default engine reads that chunk's parameters into the padding and refuses the packet, while DPKT (and Scapy) still yield the DATA records before it, named in the DPKT row; and an IPv6 Payload Length of 0, which dpkt runs to the end of the frame and the default engine reads as empty.

Tests: the issue's three frames (an unaligned last I-DATA fragment, unaligned I-DATA then DATA, a Length-5 HEARTBEAT then DATA), the walk's edge cases and the gap join the #3188 table, now compared with the default engine; CAPTURE's unaligned I-DATA fragments make the DPKT engine complete a message end to end. They fail on an origin/develop export; the SCTP adapter code is at 100% statement and branch coverage. The #1739 sweep's UNRELATED lists the common header's 12 octets for toolkit/dpkt.py. tests/toolkit, tests/foundation, tests/project, tests/protocols/*.py and tests/*.py pass, and the Sphinx-gated tests/project modules in a fresh docs venv.

@github-actions github-actions Bot added this to the PyPCAPKit v1.10 milestone Nov 29, 2026
@JarryShaw JarryShaw moved this to In review in PyPCAPKit Nov 29, 2026
@JarryShaw JarryShaw added feat Pull requests that add a new capability (feat: subject prefix) review: running A cross-review is in flight against the current head - no verdict yet labels Nov 29, 2026
@read-the-docs-community

read-the-docs-community Bot commented Nov 29, 2026 •

Copy link
Copy Markdown

Documentation build overview

📚 PyPCAPKit | 🛠️ Build #36239883 | 📁 Comparing fda3ad5 against latest (483c282)

  🔍 Preview build  

4 files changed
± genindex.html
± pcapkit/toolkit/3rdparty.html
± _modules/pcapkit/toolkit/dpkt.html
± pcapkit/foundation/engines/index.html

…isreads unaligned chunks (#3217)

dpkt 1.9.8 pads DATA chunks alone, so it misplaces the chunks after any
other unaligned one and decodes no SCTP layer where one ends the packet.
toolkit.dpkt._sctp_chunks walks such a packet again from its octets,
padding every chunk to four octets (RFC 9260 section 3.2), and the
adapter feeds the records the default engine does wherever that engine
decodes the SCTP layer. The engines page's DPKT row keeps the gap left,
behind VLAN tag stacks dpkt misplaces the layers behind (#1646), and
names the packets the default engine refuses for a last chunk cut
inside its padding, whose DATA records DPKT still reads.
@JarryShaw

Copy link
Copy Markdown
Owner Author

Good to go at fda3ad5fb, after a Sonnet cross-review plus my check of the fold.

  • The re-walk matches toolkit.pcap.sctp_reassembly across about 12k fuzzed frames: the three issue cases, bundled DATA, IPv6, tunnels, options and trailers. The 15 new tests fail on develop.
  • There are two pinned divergences, both now stated in the body and on the engines page:
  • The fold adds only that pinned row and the docs clause, which I checked in git diff.

@JarryShaw JarryShaw added review: good-to-go Cross-review at the current head says ready; CI state is separate and removed review: running A cross-review is in flight against the current head - no verdict yet labels Nov 29, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Coverage: 94.97% (unit tier, Python 3.15, fda3ad5fb, Unit Tests run success)

Package Statements Missed Branches Partial Cover
pcapkit (top level) 116 4 20 2 95.59%
pcapkit/const 22386 224 3186 191 98.28%
pcapkit/corekit 3160 83 1058 40 96.85%
pcapkit/dumpkit 423 3 148 5 98.60%
pcapkit/foundation 4348 24 1364 26 99.12%
pcapkit/interface 112 4 40 3 95.39%
pcapkit/protocols 28918 152 7662 127 99.23%
pcapkit/toolkit 1251 35 458 9 96.61%
pcapkit/utilities 638 7 176 5 98.53%
pcapkit/vendor 6575 2396 1478 258 60.24%

Per-file detail: the coverage-html artifact of this run.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feat Pull requests that add a new capability (feat: subject prefix) review: good-to-go Cross-review at the current head says ready; CI state is separate

Projects

Status: In review

Development

Successfully merging this pull request may close these issues.

1 participant